package com.itheima.reggie.controller;


import com.itheima.reggie.common.R;


import com.itheima.reggie.domain.Dish;

import com.itheima.reggie.domain.PageBean;
import com.itheima.reggie.dto.DishDto;
import com.itheima.reggie.service.DishFlavorService;
import com.itheima.reggie.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/dish")
public class DishController {

    @Autowired
    private DishFlavorService dishFlavorService;

    @Autowired
    private DishService dishService;

    @PostMapping
    public R addDish(@RequestBody DishDto dishDto){


      dishService.addDish(dishDto);

        return R.success(null);
    }

    //菜品分页查询
    @GetMapping("/page")
    public R page(int page,int pageSize,String name){

        PageBean p = dishService.findPage(page, pageSize, name);
        System.out.println(p);
        return R.success(p);
    }

    //菜品修改数据回显
    @GetMapping("{id}")
    public R selectById(@PathVariable Long id){

        DishDto dishDto = dishService.selectById(id);

        return R.success(dishDto);

    }

    //菜品修改
    @PutMapping
    public R update(@RequestBody DishDto dishDto){

        dishService.update(dishDto);


        return R.success(null);
    }


    //添加套餐中的添加菜品
    @GetMapping("list")
    public R list(Dish dish){

        List<DishDto> dishs = dishService.findByCategoryId(dish);

        return R.success(dishs);
    }

    //根据id删除和批量删除
    @DeleteMapping
    public R deleteById(Long[] ids){

        dishService.removeByIds(Arrays.asList(ids));

        return R.success(null);
    }

    //单个停售和批量停售
    @PostMapping("status/{status}")
    public R status(@PathVariable int status,Long[] ids){

       dishService.getStatus(status, ids);

        return R.success(null);
    }



}
